package JUC;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;

public class LzxTest {
    public static void main(String[] args) {
        List<String> list = Arrays.asList(new String[10]);

        ExecutorService executor = Executors.newFixedThreadPool(Math.min(list.size(), 100));

        List<String> collect = list.stream().map(a -> CompletableFuture.supplyAsync(() -> {
            // 操作代码.....
            try {
                Thread.sleep(10);
                return a+"lzx";
            } catch (InterruptedException e) {
                e.printStackTrace();
                return "-1";
            }

        }, executor)).collect(Collectors.toList()).stream().map(CompletableFuture::join).collect(Collectors.toList());
        collect.forEach(System.out::println);
    }
}
